home *** CD-ROM | disk | FTP | other *** search
/ Info-Mac 3 / Info_Mac_1994-01.iso / Applications / ARTAbrot 1.0 / About_ARTAbrot.c < prev    next >
Text File  |  1993-08-23  |  7KB  |  186 lines

  1. /* About_ARTAbrot */
  2.  
  3. /* File name: About_ARTAbrot */
  4. /* Function: Handle a modeless dialog */
  5. /*            This dialog operates like a window, it is not modal. */
  6. /*           Opened by:    */
  7. /*           Closed by:     */
  8. /*           Purpose:       
  9. History: 8/18/93 Original by George Warner
  10.    */
  11.  
  12.  
  13. #include "ComUtil_ARTAbrot.h"    /* Common */
  14.  
  15. #include "AB_Alert.h"    /* Alert */
  16. #include "About_ARTAbrot.h"    /* This modeless dialog */
  17.  
  18.  
  19.  
  20.  
  21. #pragma segment About_ARTAbrot
  22.  
  23. static Boolean        ExitDialog;                    /* Flag to exit dialog */
  24.  
  25. /* ======================================================= */
  26.  
  27.  
  28. /* ======================================================= */
  29.  
  30. /* Routine: Init_About_ARTAbrot */
  31. /* Purpose: This procedures purpose is to set the window pointer to nil, */
  32. /* this is used to tell the other routines */
  33.  
  34. void Init_About_ARTAbrot()
  35. {
  36.     WPtr_About_ARTAbrot = NIL;    /* Initialize to say that the dialog is not yet active */
  37. }
  38.  
  39. /* ======================================================= */
  40.  
  41. /* Routine: Moved_About_ARTAbrot */
  42. /* Purpose: We were moved, possibly to another screen and screen depth */
  43.  
  44. void Moved_About_ARTAbrot(WindowPtr theWindow)/* Moved this window */
  45. {
  46. WindowPtr    SavePort;                        /* Place to save the last port */
  47.  
  48.     if (WPtr_About_ARTAbrot == theWindow) {    /* Only do if the window is us */
  49.         GetPort(&SavePort);                    /* Save the current port */
  50.         SetPort(theWindow);                    /* Set the port to my window */
  51.  
  52.         SetPort(SavePort);                    /* Restore the old port */
  53.     }
  54. }
  55.  
  56. /* ======================================================= */
  57.  
  58. /* Routine: Update_About_ARTAbrot */
  59. /* Purpose: This procedures purpose is to refresh this window, update it, */
  60. /* when we are uncovered by another window.  */
  61.  
  62. void Update_About_ARTAbrot(WindowPtr theWindow)
  63. {
  64. GrafPtr    SavedPort;                            /* Save the current port so we can restore to it */
  65. Rect    rTempRect;                            /* Temporary rectangle variable */
  66. RGBColor    Saved_ForeColor;                /* Place to save colors */
  67. RGBColor    Saved_BackColor;                /* Place to save colors */
  68. RGBColor    DrawingColor;                    /* Place to make colors */
  69.  
  70.     /* Only do if we are the window to update */
  71.     if ((WPtr_About_ARTAbrot != nil) && (theWindow == WPtr_About_ARTAbrot)) {
  72.         GetPort(&SavedPort);                /* Get the current port */
  73.         SetPort(theWindow);                    /* Point to our port for drawing in our window */
  74.  
  75.         GetForeColor(&Saved_ForeColor);        /* Save the fore color */
  76.         GetBackColor(&Saved_BackColor);        /* Save the back color */
  77.  
  78.         RGBForeColor(&Black_ForeColor);        /* Set the fore color to Black */
  79.         RGBBackColor(&White_BackColor);        /* Set the back color to White */
  80.  
  81.         DrawingColor.red = 0x0000;  DrawingColor.green = 0x0000;  DrawingColor.blue = 0xEEEE;/* Set the color */
  82.         RGBForeColor(&DrawingColor);        /* Set the fore color */
  83.  
  84.         /* Draw a string of text, Static Text */
  85.         SetRect(&rTempRect, 37,94,199,159);
  86.         GetIndString(sTemp,Res_Dlg_Static_Text5,1);    /* Get the string */
  87.         TextBox(&sTemp[1], sTemp[0], &rTempRect,teJustLeft);
  88.  
  89.         RGBForeColor(&Black_ForeColor);        /* Set the fore color to Black */
  90.         TextSize(12);
  91.         TextFont(systemFont);                /* Select the Font that we want */
  92.         TextFace(0);                        /* Select the style that we want */
  93.  
  94.         RGBForeColor(&Saved_ForeColor);        /* Restore the fore color */
  95.         RGBBackColor(&Saved_BackColor);        /* Restore the back color */
  96.  
  97.         DrawDialog(theWindow);                /* Draw the rest of the controls */
  98.         SetPort(SavedPort);                    /* Restore the port that we saved at the start */
  99.     }
  100. }
  101.  
  102. /* ======================================================= */
  103.  
  104. /* Routine: Open_About_ARTAbrot */
  105. /* Purpose: This procedures purpose is to open this window and set all */
  106. /* of the initial conditions, such as default edit text. */
  107.  
  108. void Open_About_ARTAbrot()
  109. {
  110.     if (WPtr_About_ARTAbrot == NIL) {
  111.         WPtr_About_ARTAbrot = GetNewDialog(Res_MD_About_ARTAbrot, NIL,  (WindowPtr)-1 );/* Bring in the dialog resource */
  112.         SetPort(WPtr_About_ARTAbrot);        /* Prepare to add conditional text */
  113.         Doing_MovableModal = true;            /* We are now in the movable modal mode */
  114.  
  115.         ShowWindow(WPtr_About_ARTAbrot);    /* Open a dialog box */
  116.         SelectWindow(WPtr_About_ARTAbrot);    /* Lets see it */
  117.     }
  118.     else
  119.         SelectWindow(WPtr_About_ARTAbrot);    /* Lets see it */
  120. }
  121.  
  122. /* ======================================================= */
  123.  
  124. /* Routine: Close_About_ARTAbrot */
  125. /* Purpose: This procedures purpose is to close this window and clear */
  126. /* the window pointer variable */
  127.  
  128. void Close_About_ARTAbrot(WindowPtr theWindow)
  129. {
  130.     /* Only close if it is us and we were open */
  131.     if ((WPtr_About_ARTAbrot != NIL) && (theWindow == WPtr_About_ARTAbrot)) {
  132.         Doing_MovableModal = false;        /* We are now out of the movable modal mode */
  133.         DisposDialog(theWindow);        /* Close on the screen and Flush the dialog out of memory */
  134.         WPtr_About_ARTAbrot = nil;        /* Make sure our other routines know that we are closed */
  135.     }
  136. }
  137.  
  138. /* ======================================================= */
  139.  
  140.  
  141. /* Routine: Do_About_ARTAbrot */
  142. /* Purpose: This procedures purpose is to handle all actions, such as buttons being pressed. */
  143. /* This is the real meat of this unit and is where the code is for acting upon the users actions. */
  144.  
  145. void Do_About_ARTAbrot(EventRecord *theEvent,WindowPtr theWindow,short itemHit)
  146. {
  147. Point    myPt;                                /* For the local mouse position */
  148. Boolean    ExitDialog;                            /* Flag to close this dialog */
  149. short    DType;                                /* Type of dialog item */
  150. Handle    DItem;                                /* Handle to the dialog item */
  151. Rect    tempRect;                            /* Temporary rectangle */
  152. ControlHandle    CItem;                        /* Control handle */
  153.  
  154.     ExitDialog = false;                        /* Do not close the dialog yet */
  155.     if ((theEvent->what == mouseDown) && (WPtr_About_ARTAbrot != nil)) {
  156.         SetPort(WPtr_About_ARTAbrot);        /* Set the port to our dialog */
  157.         myPt = theEvent->where;                /* Get the position where the mouse was pressed */
  158.         GlobalToLocal(&myPt);                /* Change from global to local location */
  159.     }
  160.  
  161.     if ((WPtr_About_ARTAbrot != nil)  && (WPtr_About_ARTAbrot  == theWindow)) {
  162.         if (theEvent->what == keyDown) {
  163.             itemHit = 0;                    /* Default to no item hit */
  164.         }
  165.  
  166.         if ((WPtr_About_ARTAbrot != NIL)  && (WPtr_About_ARTAbrot  == theWindow)) {
  167.             myPt = theEvent->where;            /* Get the position where the mouse was pressed */
  168.             GlobalToLocal(&myPt);            /* Change from global to local location */
  169.  
  170.             GetDItem(theWindow, itemHit,&DType,&DItem,&tempRect);/* Get which item was pressed */
  171.             CItem = (ControlHandle)DItem;    /* Change the pointer for getting to the control */
  172.  
  173.             /* Handle it real time */
  174.             if (itemHit ==Res_Dlg_OK2) {    /* Handle the Button being pressed */
  175.                 Add_UserEvent(UserEvent_Close_Window,Res_MD_About_ARTAbrot,0,0,nil);/* Open a modeless dialog */
  176.                 Play_The_Sound(Snd_Bart__Cooool);    /* Play my sound */
  177.             }
  178.         }
  179.     }
  180.  
  181.     if (ExitDialog) {                        /* Do the close of the dialog */
  182.         Close_About_ARTAbrot(WPtr_About_ARTAbrot);
  183.         WPtr_About_ARTAbrot = nil;            /* Clear it for future checks */
  184.     }
  185. }
  186.